home *** CD-ROM | disk | FTP | other *** search
- Path: news-relay.eworld.com!zdc!zippo!drn
- From: Clarence Chiang
- Newsgroups: comp.lang.c++
- Subject: Re: Template constructor problem
- Date: 1 Apr 1996 12:09:56 -0800
- Organization: Zippo
- Sender: http@doc.zippo.com
- Message-ID: <4jpd6k$2nu@doc.zippo.com>
- NNTP-Posting-Host: doorstop.spiderisland.com
-
- In article <4jjtgf$ebo@csugrad.cs.vt.edu>, rsuri@csugrad.cs.vt.edu says...
- >
- >Ok, take this code using g++ v2.7
- >
- >queue.h:
- >
- >template <class QueueItem> class Queue {
- > private:
- > QueueItem buffer[100];
- > int head, tail, count;
- >
- > public:
- > Queue();
- > void Insert (QueueItem item);
- > QueueItem Remove();
- > int Size();
- > ~Queue();
- >};
- >
- >template <class QueueItem>
- >Queue<QueueItem>::Queue() : count(0), head(0), tail(0) {}
- >
- >.....[the rest of the mothods]
- >
- >
- >main.cc:
- >
- >#include<stdio.h>
- >#include "queue.h"
- >
- >Queue<int> myqueue;
- >
- >main () {
- >
- >}
- >
- >
- >Compiler error when linking:
- >collect2: ld returned 1 exit status
- >/usr/lib/cmplrs/cc/ld:
- >Undefined:
- >Queue<int>::Queue(void)
- >
- >
- >If I don't declare a queue object, then I don't get the linker error.
- >Any suggestion?? Thanks in advance.
- >
- >-Raj
- >
-
- The compiler is correct. According to the C++ language specification, if you
- declare a ctor that takes parameter(s). You must also declare one that doesn't
- take parameter (i.e. Queue<QueueItem>::Queue(void) ). Obviously g++ is expecting
- there is one. The compiler shouldn't wait til link time to issue an error, it
- should check for it and give out a compile-time error.
-
- Clarence Chiang
- Spider Island Software
-